package com.resource.converter;

import com.resource.dto.OfficeProjectInfoDto;
import com.resource.dto.OfficeProjectLinkmanDto;
import com.resource.request.OfficeProjectLinkmanRequest;
import com.resource.request.OfficeProjectRequest;
import com.resource.response.OfficeProjectInfoResponse;
import com.resource.response.OfficeProjectLinkmanResponse;
import org.mapstruct.*;

import java.util.List;

/**
 * 泛微系统返回对象转换
 *
 * @Author: xianggaoxiong
 * @Date: 16:29 2020/9/22
 */
@Mapper(componentModel = "spring")
public interface ProjectConverter {
    // -----------------------------------------------response转换----------------------------------------

    /**
     * 将response转成dto
     *
     * @param response
     * @return
     */
    @Mappings({@Mapping(source = "manager_id", target = "managerId"),
            @Mapping(source = "manager_name", target = "managerName"),
            @Mapping(source = "manager_number", target = "managerNumber"),
            @Mapping(source = "manager_begintime", target = "managerBegintime"),
            @Mapping(source = "manager_endtime", target = "managerEndtime"),
            @Mapping(source = "manager_type", target = "managerType"),
            @Mapping(source = "manager_person", target = "managerPerson"),
            @Mapping(source = "manager_examine", target = "managerExamine"),
            @Mapping(source = "manager_monitor", target = "managerMonitor"),
            @Mapping(source = "manager_explain", target = "managerExplain"),
            @Mapping(source = "manager_team", target = "managerTeam"),
            @Mapping(source = "manager_template", target = "managerTemplate"),
            @Mapping(source = "manager_fast", target = "managerFast"),
            @Mapping(source = "manager_level", target = "managerLevel"),
            @Mapping(source = "manager_state", target = "managerState"),
            @Mapping(source = "manager_appraisal", target = "managerAppraisal"),
            @Mapping(source = "manager_appraisal_feedback", target = "managerAppraisalFeedback"),
            @Mapping(source = "manager_remark", target = "managerRemark"),
            @Mapping(source = "attachment_id", target = "attachmentId"),
            @Mapping(source = "attachment_name", target = "attachmentName"),
            @Mapping(source = "manager_creater", target = "managerCreater"),
            @Mapping(source = "created_at", target = "createdAt"),
            @Mapping(source = "updated_at", target = "updatedAt"),
            @Mapping(source = "deleted_at", target = "deletedAt"),
            @Mapping(source = "complete_date", target = "completeDate"),
            @Mapping(source = "is_overdue", target = "isOverdue"), @Mapping(source = "progress", target = "progress"),
            @Mapping(source = "manager_person_name", target = "managerPersonName"),
            @Mapping(source = "manager_examine_name", target = "managerExamineName"),
            @Mapping(source = "manager_monitor_name", target = "managerMonitorName"),
            @Mapping(source = "manager_creater_name", target = "managerCreaterName"),
            @Mapping(source = "team_person_name", target = "teamPersonName"),
            @Mapping(source = "team_person", target = "teamPerson"),
            @Mapping(source = "manager_fast_name", target = "managerFastName"),
            @Mapping(source = "manager_level_name", target = "managerLevelName"),
            @Mapping(source = "type_name", target = "typeName"),
            @Mapping(source = "manager_state_name", target = "managerStateName"),
            @Mapping(source = "data_id", target = "dataId"),
            @Mapping(source = "field_1", target = "managerCustomer"),
            @Mapping(source = "field_3", target = "managerCompany"),
            @Mapping(source = "field_5", target = "managerGrade"),
            @Mapping(source = "field_6", target = "consignment"),
            @Mapping(source = "field_7", target = "planTime"),
            @Mapping(source = "field_27", target = "relationContract"),
            @Mapping(source = "row_create_time", target = "createTime"),
            @Mapping(source = "raw_field_25", target = "rawManagerLevel"),
            @Mapping(source = "raw_field_1", target = "rawManagerCustomer"),
            @Mapping(source = "raw_field_3", target = "rawManagerCompany"),
            @Mapping(source = "raw_field_5", target = "rawManagerGrade"),
            @Mapping(source = "raw_field_6", target = "rawConsignment"),
            @Mapping(source = "raw_field_27", target = "rawRelationContract")})
    OfficeProjectInfoDto responseToDto(OfficeProjectInfoResponse response);

    /**
     * 将dto转成response
     *
     * @param dto
     * @return
     */
    @InheritInverseConfiguration
    OfficeProjectInfoResponse dtoToResponse(OfficeProjectInfoDto dto);

    /**
     * 将list的response转成list的dto
     *
     * @param response
     * @return
     */
    List<OfficeProjectInfoDto> responseToDto(List<OfficeProjectInfoResponse> response);

    /**
     * 联系人转换
     *
     * @param responses
     * @return
     */
    @IterableMapping(qualifiedByName = "linkman")
    List<OfficeProjectLinkmanDto> linkmanToList(List<OfficeProjectLinkmanResponse> responses);

    /**
     * 联系人映射
     *
     * @param source
     * @return
     */
    @Named("linkman")
    @Mapping(source = "detail_data_id", target = "detailDataId")
    @Mapping(source = "field_21", target = "linkmanName")
    @Mapping(source = "field_22", target = "linkmanPhone")
    @Mapping(source = "field_23", target = "linkmanPosition")
    @Mapping(source = "field_24", target = "linkmanRemarks")
    OfficeProjectLinkmanDto linkmanResponseToDto(OfficeProjectLinkmanResponse source);

    // -----------------------------------------------request转换----------------------------------------

    /**
     * 将request转成dto
     *
     * @param request
     * @return
     */
    @Mappings({@Mapping(source = "user_id", target = "userId"), @Mapping(source = "manager_id", target = "managerId"),
            @Mapping(source = "manager_name", target = "managerName"),
            @Mapping(source = "manager_number", target = "managerNumber"),
            @Mapping(source = "manager_begintime", target = "managerBegintime"),
            @Mapping(source = "manager_endtime", target = "managerEndtime"),
            @Mapping(source = "manager_type", target = "managerType"),
            @Mapping(source = "manager_person", target = "managerPerson"),
            @Mapping(source = "manager_examine", target = "managerExamine"),
            @Mapping(source = "manager_monitor", target = "managerMonitor"),
            @Mapping(source = "manager_explain", target = "managerExplain"),
            @Mapping(source = "manager_team", target = "managerTeam"),
            @Mapping(source = "manager_template", target = "managerTemplate"),
            @Mapping(source = "manager_fast", target = "managerFast"),
            @Mapping(source = "manager_level", target = "managerLevel"),
            @Mapping(source = "manager_state", target = "managerState"),
            @Mapping(source = "manager_appraisal", target = "managerAppraisal"),
            @Mapping(source = "manager_appraisal_feedback", target = "managerAppraisalFeedback"),
            @Mapping(source = "manager_remark", target = "managerRemark"),
            @Mapping(source = "attachment_id", target = "attachmentId"),
            @Mapping(source = "attachment_name", target = "attachmentName"),
            @Mapping(source = "manager_creater", target = "managerCreater"),
            @Mapping(source = "created_at", target = "createdAt"),
            @Mapping(source = "updated_at", target = "updatedAt"),
            @Mapping(source = "deleted_at", target = "deletedAt"),
            @Mapping(source = "complete_date", target = "completeDate"),
            @Mapping(source = "is_overdue", target = "isOverdue"), @Mapping(source = "progress", target = "progress"),
            @Mapping(source = "manager_person_name", target = "managerPersonName"),
            @Mapping(source = "manager_examine_name", target = "managerExamineName"),
            @Mapping(source = "manager_monitor_name", target = "managerMonitorName"),
            @Mapping(source = "manager_creater_name", target = "managerCreaterName"),
            @Mapping(source = "team_person_name", target = "teamPersonName"),
            @Mapping(source = "team_person", target = "teamPerson"),
            @Mapping(source = "manager_fast_name", target = "managerFastName"),
            @Mapping(source = "manager_level_name", target = "managerLevelName"),
            @Mapping(source = "type_name", target = "typeName"),
            @Mapping(source = "manager_state_name", target = "managerStateName"),
            @Mapping(source = "data_id", target = "dataId"),
            @Mapping(source = "field_1", target = "managerCustomer"),
            @Mapping(source = "field_3", target = "managerCompany"),
            @Mapping(source = "field_5", target = "managerGrade"),
            @Mapping(source = "field_6", target = "consignment"),
            @Mapping(source = "field_7", target = "planTime"),
            @Mapping(source = "field_27", target = "relationContract"),
            @Mapping(source = "create_time", target = "createTime"),
            @Mapping(source = "raw_field_25", target = "rawManagerLevel"),
            @Mapping(source = "raw_field_1", target = "rawManagerCustomer"),
            @Mapping(source = "raw_field_3", target = "rawManagerCompany"),
            @Mapping(source = "raw_field_5", target = "rawManagerGrade"),
            @Mapping(source = "raw_field_6", target = "rawConsignment"),
            @Mapping(source = "raw_field_27", target = "rawRelationContract")})
    OfficeProjectInfoDto requestToDto(OfficeProjectRequest request);

    /**
     * 将dto转成Request
     *
     * @param dto
     * @return
     */
    @InheritInverseConfiguration
    OfficeProjectRequest dtoToRequest(OfficeProjectInfoDto dto);

    /**
     * 将list的request转成list的dto
     *
     * @param request
     * @return
     */
    List<OfficeProjectInfoDto> requestToDto(List<OfficeProjectInfoDto> request);

    /**
     * 联系人转换
     *
     * @param request
     * @return
     */
    @IterableMapping(qualifiedByName = "linkmanRequest")
    List<OfficeProjectLinkmanDto> linkmanRequestToList(List<OfficeProjectLinkmanRequest> request);

    /**
     * 联系人映射
     *
     * @param source
     * @return
     */
    @Named("linkmanRequest")
    @Mapping(source = "detail_data_id", target = "detailDataId")
    @Mapping(source = "field_21", target = "linkmanName")
    @Mapping(source = "field_22", target = "linkmanPhone")
    @Mapping(source = "field_23", target = "linkmanPosition")
    @Mapping(source = "field_24", target = "linkmanRemarks")
    OfficeProjectLinkmanDto linkmanRequestToDto(OfficeProjectLinkmanRequest source);

}
